<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-has="'system:SysOauth2:add'" type="primary" icon="plus">{{
          $t('m.common.button.add')
        }}
      </a-button>
    </div>

    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange">
      <template slot="serialNum" slot-scope="text,record,index">
        {{ (ipagination.current - 1) * ipagination.pageSize + parseInt(index) + 1 }}
      </template>
      <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'system:SysOauth2:edit'">{{ $t('m.common.button.update') }}</a>
          <a-divider type="vertical"/>
          <a @click="handleChangeSecret(record)" v-has="'system:SysOauth2:edit'">{{ $t('m.system.oauth2Manage.other.changeSecret') }}</a>
          <a-divider type="vertical"/>
          <a-popconfirm :title="$t('m.common.tip.delete_confirm')" v-has="'system:SysOauth2:del'"
                        @confirm="() => handleDelete(record.id)" v-test>
            <a>{{ $t('m.common.button.delete') }}</a>
          </a-popconfirm>
        </span>
    </a-table>

    <SysOauth2Modal ref="modalForm" @ok="modalFormOk"></SysOauth2Modal>

    <SysOauth2SecretModal ref="secretModal" @ok="modalFormOk"></SysOauth2SecretModal>
  </a-card>
</template>

<script>

import {YcListMixin} from '@/mixins/YcListMixin'
import SysOauth2Modal from './modules/SysOauth2Modal'
import YchConstant from "@/api/YchConstant";
import SysOauth2SecretModal from './modules/SysOauth2SecretModal'

export default {
  name: "SysOauth2List",
  mixins: [YcListMixin],
  components: {
    SysOauth2Modal,
    SysOauth2SecretModal
  },
  data() {
    return {
      columns: [
        {
          title: this.$t('m.common.label.number'),
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          scopedSlots: {customRender: 'serialNum'},
        },
        {
          title: this.$t('m.system.oauth2Manage.entity.clientId'),
          align: "center",
          width: 150,
          dataIndex: 'clientId'
        },
        {
          title: this.$t('m.system.oauth2Manage.entity.clientSecret'),
          align: "center",
          width: 180,
          dataIndex: 'clientSecret'
        },
        {
          title: this.$t('m.system.oauth2Manage.entity.clientName'),
          align: "center",
          width: 150,
          dataIndex: 'clientName'
        },
        {
          title: this.$t('m.system.oauth2Manage.entity.clientIdIssuedAt'),
          align: "center",
          width: 150,
          dataIndex: 'clientIdIssuedAt'
        },
        {
          title: this.$t('m.common.label.operate'),
          dataIndex: 'action',
          align: "center",
          width: 150,
          scopedSlots: {customRender: 'action'},
        }
      ],
      url: {
        list: YchConstant.PREFIX_SYSTEM + "/oauth2/list",
        delete: YchConstant.PREFIX_SYSTEM + "/oauth2/delete",
      },
    }
  },
  methods: {
    handleChangeSecret(record) {
      this.$refs.secretModal.open(record)
    }
  }
}
</script>
